package com.mercenary.wein.screenControl.ui;

import com.mercenary.wein.screenControl.bean.GroupMetaBean;
import com.mercenary.wein.screenControl.service.GroupService;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

//这一块我直接把新建分组名和信息写一块@涂笑
public class TwoInputDialog extends JDialog {
	JPanel jp = new JPanel(new  BorderLayout());
	JPanel jp1 = new JPanel(new BorderLayout());
	JPanel jp2 = new JPanel(new BorderLayout());
	JPanel jp3 = new JPanel();

	static GroupService groupService = new GroupService();

	private GroupComboBox comboBox = new GroupComboBox();

	public void registerGroupComboBox(GroupComboBox comboBox){
		this.comboBox = comboBox;
	}

	public void notifyGroupComboBox(GroupMetaBean gmb){
		comboBox.addItem(gmb);
	}

	public TwoInputDialog(JFrame jf) {

		super(jf, "对话框");
		this.setVisible(true);
		add(jp);
		JButton jb1 = new JButton("确定");
		JButton jb2 = new JButton("取消");
		JLabel jl = new JLabel("请输入分组名称：");
		final JTextField groupname =new JTextField();
		JLabel j2 = new JLabel("请输入信息：");
		final JTextField message =new JTextField();
		jp.setPreferredSize(new  Dimension(400,200));
		jp1.setLayout(new BorderLayout());
		jp1.add(jl,BorderLayout.NORTH);
		jp1.add(groupname,BorderLayout.CENTER);
		jp2.add(j2,BorderLayout.NORTH);
		jp2.add(message,BorderLayout.CENTER);
		groupname.setPreferredSize(new  Dimension(80,20));
		this.setSize(300, 200);
		this.setLocationRelativeTo(jf);
		//jl.setHorizontalAlignment(JLabel.CENTER);
		jp3.add(jb1);
		jp3.add(jb2);
		jp.add(jp1, BorderLayout.NORTH);
		jp.add(jp2, BorderLayout.CENTER);
		jp.add(jp3, BorderLayout.SOUTH);
		jb1.addActionListener(new ActionListener() {



			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				String gname = groupname.getText();
				notifyGroupComboBox(groupService.addGroup(gname));
				dispose();
			}


		});
		jb2.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent arg0) {
				dispose();

			}

		});
	}}


